<?php
class ControllerCommunityCommunityHeader extends Controller{
    public function index(){
        $this->language->load('community/community_header');

        if($this->customer->isLogged()){
            $user_id=$this->customer->getForumUserId();

            if(!isset($user_id)){
                echo '<script type="text/javascript">alert("' . $this->language->get('forum_user_name_not_set') . '"); top.location="' . $this->url->link('community/ucp') . '&mode=p&action=eas' . '";</script>';

                exit;
            }
        }
                
        $this->document->setTitle($this->language->get('heading_title'));

        //detect if user login
        if($this->customer->isLogged()){
            $this->data['is_user_login']=TRUE;
        }else{
            $this->data['is_user_login']=FALSE;
        }

        $this->data['text_ucp']=$this->language->get('text_ucp');

        if($this->customer->getForumUserNotifyPm()==0){
            $this->data['text_new_message']=sprintf($this->language->get('text_new_message'),'0');
        }else{
            $this->data['text_new_message']=sprintf($this->language->get('text_new_message'),$this->customer->getForumUserNewPm());
        }

        $this->data['text_quick_nav']=$this->language->get('text_quick_nav');
        $this->data['text_claim_daily_bonus']=$this->language->get('text_claim_daily_bonus');
        $this->data['text_view_your_topics']=$this->language->get('text_view_your_topics');
        $this->data['text_view_your_posts']=$this->language->get('text_view_your_posts');
        $this->data['text_unanswered__topics']=$this->language->get('text_unanswered__topics');
        $this->data['text_search_button_title']=$this->language->get('text_search_button_title');
        $this->data['text_search_forum']=$this->language->get('text_search_forum');
        $this->data['text_search_submit_button_value']=$this->language->get('text_search_submit_button_value');
        $this->data['text_advanced_search']=$this->language->get('text_advanced_search');
        $this->data['text_advanced_search_button_title']=$this->language->get('text_advanced_search_button_title');

        $this->data['new_message_link']=$this->url->link('community/ucp','mode=pm','SSL');
        $this->data['ucp_link']=$this->url->link('community/ucp');
        $this->data['view_your_post_link']=$this->url->link('community/ucp');
        $this->data['search_link']=$this->url->link('community/search');
        $this->data['topics_link']=$this->url->link('community/profile','action=t&uid=' . $this->customer->getForumUserId(),'SSL');
        $this->data['posts_link']=$this->url->link('community/profile','action=p&uid=' . $this->customer->getForumUserId(),'SSL');
        $this->data['unanswered_topics_link']=$this->url->link('community/search', 'mode=unanswered', 'SSL');

		if(file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/community/community_header.tpl')){
            $this->template=$this->config->get('config_template') . '/template/community/community_header.tpl';
		}else{
            $this->template='default/template/community/community_header.tpl';
		}

        $this->render();
  	}

    public function bonus(){
        $this->language->load('community/community_header');
        $this->load->model('community/community_header');

        $now_time=time();
        $json=array();

        //detect claim records
        $history=$this->model_community_community_header->getLatestDailyForumPointClaimTime();

        if($history){
            if($history['add_time']+60*60*24>=$now_time){
                $left_time=ceil(($history['add_time']+60*60*24-$now_time)/3600);

                if($left_time){
                    $json['error'] = sprintf($this->language->get('error_max_claim_hour'),$left_time);
                }else{
                    $json['error'] = sprintf($this->language->get('error_max_claim_second'),5);
                }
            }
        }

        if($this->customer->getMasterSlave()=='sl'){
            $json['error'] = sprintf($this->language->get('error_slave_account'),$this->url->link('account/forum_point'));
        }

        if(!$this->customer->isLogged()){
            $json['error'] = $this->language->get('error_not_logged');
        }

        if (!isset($json['error'])) {
            $this->model_community_community_header->addDailyForumPoints($now_time);

            $json['success'] = sprintf($this->language->get('daily_bonus_success'),$this->config->get('daily_bonus'),$this->url->link('account/forum_point'));
        }

        $this->response->setOutput(json_encode($json));
    }
}
?>